package com.xgkj.diyiketang.fragment;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.xgkj.diyiketang.EatShowApp;
import com.xgkj.diyiketang.R;
import com.xgkj.diyiketang.activity.BangDingPhoneActivity;
import com.xgkj.diyiketang.activity.MainActivity;
import com.xgkj.diyiketang.activity.SearchZhiboActivity;
import com.xgkj.diyiketang.activity.YuZhiBoActivity;
import com.xgkj.diyiketang.activity.data.LiveListAdapter;
import com.xgkj.diyiketang.activity.data.SubjectAdapter;
import com.xgkj.diyiketang.activity.data.XueXiaoAdapter;
import com.xgkj.diyiketang.data.AdvertiseInfo;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.data.SchoolInfo;
import com.xgkj.diyiketang.http.engine.ShowToastTaskEventListener;
import com.xgkj.diyiketang.http.engine.TaskResultCode;
import com.xgkj.diyiketang.task.AdvertisementTask;
import com.xgkj.diyiketang.task.GetUserDetailTask;
import com.xgkj.diyiketang.task.LiveListTask;
import com.xgkj.diyiketang.task.SchoolListTask;
import com.xgkj.diyiketang.util.DialogUtil;
import com.xgkj.diyiketang.util.NoDataUtil;
import com.xgkj.diyiketang.util.PopupHelper;
import com.xgkj.diyiketang.util.SharedUtils;
import com.xgkj.diyiketang.weidget.PullToRefreshListView;
import com.xgkj.diyiketang.yizhibo.Constants;
import com.xgkj.diyiketang.yizhibo.Preferences;

import java.util.ArrayList;
import java.util.List;

import static com.tencent.open.utils.Global.getSharedPreferences;

/**
 * Created by XCKJ_Paladowow on 2016/7/15.
 */
public class ZhiBoFragment extends BaseFragment {
    @Override
    protected int getContentViewId() {
        return 0;
    }//implements PullToRefreshListView.OnRefreshListener, PullToRefreshListView.OnLoadDataListener, View.OnClickListener, PullToRefreshListView.OnScrollListener {
 /*   private static final String TAG = ZhiBoFragment.class.getSimpleName();
    private Context mContext;
    private View view;
    private TextView mToZhibo;
    //    private boolean isAnchor;
    private String canLive;
    private PullToRefreshListView mListView;
    //    private PullToRefreshListView mHotListView;
//    private PullToRefreshListView mAttentionListView;
    private LiveListAdapter mAdapter;
    //    private LiveListAdapter mHotAdapter;
//    private LiveListAdapter mAttentionAdapter;
    private int currentPage = 1;
    private int size = 20;
    //    private int currentPage_h = 1;
//    private int currentPage_a = 1;
    private int mTuijianListTaskId = -1;
    private YZBSdk mYZBSdk;
    //    private RadioGroup zhiboTypeGroup;
//    private RadioButton newButton;
//    private RadioButton hotButton;
//    private RadioButton attentionButton;
    private int mZhiboType;
    private String versionCode;

    private LinearLayout xuanzeLayout;
    private RelativeLayout chooseRegion;
    private TextView region;
    private RelativeLayout chooseKemu;
    private TextView kemu;
    private RelativeLayout choosePaixu;
    private TextView paixu;
    private RelativeLayout chooseLeiBie;
    private TextView leibie;
    private String mLeiBie;
    private PopupHelper mLeiBiePopWindow;
    private PopupHelper mRegionPopWindow;
    private PopupHelper mSubjectPopWindow;
    private PopupHelper mOrderPopWindow;
    private SubjectAdapter mSubjectAdapter;
    private SubjectAdapter mOrderAdapter;
    private XueXiaoAdapter mXuexiaoAdapter;
    private SubjectAdapter mLeibieAdapter;
    private SubjectAdapter mRegionAdapter;
    private String mSubjectNo;
    private String mRegion;
    private NoDataUtil noDataUtil;
    private ImageView zhiboSearch;
    private int schoolListTaskId = -1;
    private int detailTaskId = -1;
    EatShowUserInfo userInfo;
    private int advertiseId = -1;
    //private ImageCycleView adView;
    private List<AdvertiseInfo> adList = new ArrayList<AdvertiseInfo>();
    private int firstListItem;

    private int isLive = -1;
    private String canStartLive;
    private View empty_view;
    private String fansNum = "0";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if (view == null) {
            view = inflater.inflate(R.layout.zhibofragment, null);

        }

        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }
        mContext = getActivity();
        getUserInfoIsLive();
        checkAppKey(Constants.APP_KEY_ID);
        mYZBSdk = YZBSdkFactory.getInstance().getYZBSdkInstance(mContext, Constants.APP_KEY_ID);
        mYZBSdk.registerApp(Constants.APP_KEY_ID, Constants.APP_KEY_SECRET);
        initView(view);
        return view;
    }

    *//*直播的 判断方法请求*//*
    public void getUserInfoIsLive() {
        GetUserDetailTask task = new GetUserDetailTask();
        task.addListener(new ForgetUserInfoTaskEventListener(mContext));
        isLive = getEatShowApp().getTaskManager().addTask(task);

    }

    class ForgetUserInfoTaskEventListener extends ShowToastTaskEventListener {
        public ForgetUserInfoTaskEventListener(Context context) {
            super(context);
        }

        @Override
        public void handleTaskCompleted(int taskId, int result, Object data) {
            super.handleTaskCompleted(taskId, result, data);
            if (taskId == isLive) {
                isLive = -1;

                // EatShowApp data1 = (EatShowApp) data;
                EatShowUserInfo data1 = (EatShowUserInfo) data;
                canStartLive = data1.getCanStartLive();
                //通过sp存储，对vip等级进行存储
                if (data1.isVip() >= 0) {
                    int vip = data1.isVip();
                    SharedUtils.putInt("vip", vip);
                }
                if (null != data1.getFans() && "0" == fansNum) {
                    fansNum = data1.getFans();
                }
                Log.e("canStartLive1::", canStartLive);
                if (getEatShowApp().getmUserInfo() != null) {
                    getEatShowApp().getmUserInfo().setCanStartLive(canStartLive);

                }

            }
        }

        @Override
        public void handleTaskError(int taskId, int errorCode, String errorMsg) {
            super.handleTaskError(taskId, errorCode, errorMsg);
        }
    }


    private void initView(View view) {
//        adView = (ImageCycleView) view.findViewById(R.id.lunbo);
        getAdList();
//        isAnchor = getEatShowApp().getmUserInfo().isHost();
        try {
            PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
            versionCode = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
//        if (getEatShowApp().getmUserInfo() != null) {
//            canLive = getEatShowApp().getmUserInfo().getCanStartLive();
//        }

        zhiboSearch = (ImageView) view.findViewById(R.id.zhibo_search);
        zhiboSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(mContext, SearchZhiboActivity.class));
            }
        });
        mToZhibo = (TextView) view.findViewById(R.id.live_prepare_btn);
        mToZhibo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.createDialog(mContext, -1, mContext.getString(R.string.prompt),
                        mContext.getString(R.string.qingxuanze), mContext.getString(R.string.quyuyue),
                        mContext.getString(R.string.quzhibo), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (Integer.parseInt(canLive) == 1) {
                                    Intent yintent = new Intent(mContext, YuZhiBoActivity.class);
                                    yintent.putExtra("FROM", "YUYUE");
                                    yintent.putExtra("FANSNUM", Integer.parseInt(fansNum));
                                    startActivity(yintent);
                                } else {
                                    Intent bangding = new Intent(mContext, BangDingPhoneActivity.class);
                                    startActivity(bangding);

                                }
                            }
                        }, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (Integer.parseInt(canLive) == 1) {
                                    Intent zintent = new Intent(mContext, YuZhiBoActivity.class);
                                    zintent.putExtra("FROM", "ZHIBO");
                                    zintent.putExtra("FANSNUM", Integer.parseInt(fansNum));
                                    startActivity(zintent);
                                } else {
                                    Intent bangding = new Intent(mContext, BangDingPhoneActivity.class);
                                    startActivity(bangding);
                                }
                            }
                        });

            }
        });
//        if (canLive == null || canLive.equals("0")) {
//            mToZhibo.setVisibility(View.GONE);
//        }

        xuanzeLayout = (LinearLayout) view.findViewById(R.id.xuanze_layout);
        chooseLeiBie = (RelativeLayout) view.findViewById(R.id.choose_leibie);
        leibie = (TextView) view.findViewById(R.id.leibie);
        chooseLeiBie.setOnClickListener(this);
        chooseRegion = (RelativeLayout) view.findViewById(R.id.choose_region);
        chooseRegion.setOnClickListener(this);
        region = (TextView) view.findViewById(R.id.region);
        chooseKemu = (RelativeLayout) view.findViewById(R.id.choose_kemu);
        chooseKemu.setOnClickListener(this);
        kemu = (TextView) view.findViewById(R.id.kemu);
        choosePaixu = (RelativeLayout) view.findViewById(R.id.choose_paixu);
        choosePaixu.setOnClickListener(this);
        paixu = (TextView) view.findViewById(R.id.paixu);
        View view1 = view.findViewById(R.id.content_layout);
        noDataUtil = new NoDataUtil(mContext, view1);

        *//**
         * windo on 16/10/19
         * 上午11:50
         *//*
//        zhiboTypeGroup = (RadioGroup) view.findViewById(R.id.zhibo_tab);
//        newButton = (RadioButton) view.findViewById(R.id.new_button);
//        hotButton = (RadioButton) view.findViewById(R.id.hot_button);
//        attentionButton = (RadioButton) view.findViewById(R.id.attention_button);
//        zhiboTypeGroup.setOnCheckedChangeListener(this);
//
//
//        mHotListView = (PullToRefreshListView) view.findViewById(R.id.zhibo_hot_list);
//        mHotListView.init(mContext,true);
//        mHotAdapter = new LiveListAdapter(mContext);
//        mHotListView.setAdapter(mHotAdapter,true);

        *//*mHotListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mHotListView.getHeaderViewsCount() > 0) {
                    position--;
                }
                if (position < 0 || position >= mHotAdapter.getCount()) return;
                EatShowUserInfo info = (EatShowUserInfo) mHotAdapter.getItem(position);

                String vid = info.getVid();


                Intent intent = new Intent(mContext, PlayerActivity.class);
                intent.putExtra(Constants.EXTRA_KEY_VIDEO_ID, vid);
                intent.putExtra("ZHIBO_LIST", mHotAdapter.getDataList());
                intent.putExtra("CURRENT_POSITION",position);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            }
        });*//*

        *//**
         * windo on 16/10/19
         * 上午11:52
         *//*
//        mHotListView.setOnRefreshListener(this);
//        mHotListView.setOnLoadDataListener(this);
//        mHotListView.setVisibility(View.GONE);
//
//        mAttentionListView = (PullToRefreshListView) view.findViewById(R.id.zhibo_attention_list);
//        mAttentionListView.init(mContext,true);
//        mAttentionAdapter = new LiveListAdapter(mContext);
//        mAttentionListView.setAdapter(mAttentionAdapter,true);

        *//*mAttentionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mAttentionListView.getHeaderViewsCount() > 0) {
                    position--;
                }
                if (position < 0 || position >= mAttentionAdapter.getCount()) return;
                EatShowUserInfo info = (EatShowUserInfo) mAttentionAdapter.getItem(position);

                String vid = info.getVid();


                Intent intent = new Intent(mContext, PlayerActivity.class);
                intent.putExtra(Constants.EXTRA_KEY_VIDEO_ID, vid);
                intent.putExtra("ZHIBO_LIST", mAttentionAdapter.getDataList());
                intent.putExtra("CURRENT_POSITION",position);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            }
        });*//*

//        mAttentionListView.setOnRefreshListener(this);
//        mAttentionListView.setOnLoadDataListener(this);
//        mAttentionListView.setVisibility(View.GONE);


        mListView = (PullToRefreshListView) view.findViewById(R.id.zhibo_list);
        mListView.setOnScrollListener(this);
        mListView.init(mContext, true);
        mAdapter = new LiveListAdapter(mContext);
        mAdapter.setOnAdapterClickListener(this);
        mListView.setAdapter(mAdapter, true);

        *//*mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mListView.getHeaderViewsCount() > 0) {
                    position--;
                }
                if (position < 0 || position >= mAdapter.getCount()) return;
                EatShowUserInfo info = (EatShowUserInfo) mAdapter.getItem(position);

                String vid = info.getVid();


                Intent intent = new Intent(mContext, PlayerActivity.class);
                intent.putExtra(Constants.EXTRA_KEY_VIDEO_ID, vid);
                intent.putExtra("ZHIBO_LIST", mAdapter.getDataList());
                intent.putExtra("CURRENT_POSITION",position);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            }
        });*//*
        mListView.setOnRefreshListener(this);
        mListView.setOnLoadDataListener(this);
        initPopWindow();
        //TODO
        View empty_view = view.findViewById(R.id.content_layout);
        noDataUtil = new NoDataUtil(mContext, empty_view);
        mZhiboType = 1;
//        getSchoolList();
        mListView.doRefresh();
//        newButton.setChecked(true);
    }

    private void getSchoolList() {
        SchoolListTask schoolListTask = new SchoolListTask();
        schoolListTask.addListener(new MyListener(mContext));
        schoolListTaskId = getEatShowApp().getTaskManager().addTask(schoolListTask);
    }

    private void initPopWindow() {
        //类别popwindow
        mLeibieAdapter = new SubjectAdapter(mContext, 5);
        mLeibieAdapter.setSelectPosition(0);
        leibie.setText((String) mLeibieAdapter.getItem(0));
        mLeiBiePopWindow = new PopupHelper(mContext, mLeibieAdapter);
        mLeiBiePopWindow.setOnDisMissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                leibie.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallxiajiantou, 0);
            }
        });

        mLeiBiePopWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mLeiBiePopWindow.dismissDropDownView();
                if (position == 0) {
                    mLeiBie = null;
                } else {
//                    mLeiBie = String.valueOf(position - 1);
                    if (String.valueOf(position - 1).equals("0")) {
                        mLeiBie = "992a1f76047e4839a9631259c033d867";
                    } else if (String.valueOf(position - 1).equals("1")) {
                        mLeiBie = "a10e3a144fd6412598c18796951386c1";
                    } else if (String.valueOf(position - 1).equals("2")) {
                        mLeiBie = "d74604615a344df3bb4c569a40e16d28";
                    } else if (String.valueOf(position - 1).equals("3")) {
                        mLeiBie = "e9fa420b2d774965b80b48727fe3e968";
                    } else if (String.valueOf(position - 1).equals("4")) {
                        mLeiBie = "31d41764f6a24099a04bc1b614289f2c";
                    } else if (String.valueOf(position - 1).equals("5")) {
                        mLeiBie = "fe45e51fee0f4d43998490cb675a9fa4";
                    }
                }
                Log.e(TAG, "onItemClick: " + mLeiBie);
                String currentLeiBie = (String) mLeibieAdapter.getItem(position);
                leibie.setText(currentLeiBie);
                mAdapter.setCurrentLeibieType(currentLeiBie);
                mLeibieAdapter.setSelectPosition(position);
                mListView.doRefresh();
            }
        });

        //地区
        mRegionAdapter = new SubjectAdapter(mContext, 6);
        mRegionAdapter.setSelectPosition(0);
        region.setText((String) mRegionAdapter.getItem(0));
        mRegionPopWindow = new PopupHelper(mContext, mRegionAdapter);
        mRegionPopWindow.setOnDisMissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                region.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallxiajiantou, 0);
            }
        });
        //df
        mRegionPopWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mRegionPopWindow.dismissDropDownView();
                if (position == 0) {
                    mRegion = null;
                } else {
                    mRegion = String.valueOf(position - 1);
                }
                String currentLeiBie = (String) mRegionAdapter.getItem(position);
                region.setText(currentLeiBie);
                mAdapter.setCurrentLeibieType(currentLeiBie);
                mRegionAdapter.setSelectPosition(position);
                mListView.doRefresh();
            }
        });


        //科目popupwindow
        mSubjectAdapter = new SubjectAdapter(mContext, 1);
        mSubjectAdapter.setSelectPosition(0);
        kemu.setText((String) mSubjectAdapter.getItem(0));
        mSubjectPopWindow = new PopupHelper(mContext, mSubjectAdapter);
        mSubjectPopWindow.setOnDisMissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                kemu.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallxiajiantou, 0);
            }
        });
        mSubjectPopWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mSubjectPopWindow.dismissDropDownView();
                if (position == 0) {
                    mSubjectNo = null;
                } else {
                    mSubjectNo = String.valueOf(position - 1);
                }

                String currentKemu = (String) mSubjectAdapter.getItem(position);
                kemu.setText(currentKemu);
                mAdapter.setCurrentKemuType(currentKemu);
                mSubjectAdapter.setSelectPosition(position);
                mListView.doRefresh();
            }
        });

//        //学校popupwindow
//        mXuexiaoAdapter = new XueXiaoAdapter(mContext);
//        mXuexiaoAdapter.setSelectPosition(0);
//        mRegionPopWindow = new PopupHelper(mContext, mXuexiaoAdapter);
//        mRegionPopWindow.setOnDisMissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                region.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallxiajiantou, 0);
//            }
//        });
//        mRegionPopWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                mRegionPopWindow.dismissDropDownView();
//                SchoolInfo info = (SchoolInfo) mXuexiaoAdapter.getItem(position);
//                if (info != null) {
//                    mSchool = info.getName();
//                }
//                region.setText(mSchool);
//                if (position == 0) {
//                    mSchool = null;
//                }
//                mXuexiaoAdapter.setSelectPosition(position);
//                mListView.doRefresh();
//            }
//        });

        //直播类型最新，最热，关注
        mOrderAdapter = new SubjectAdapter(mContext, 4);
        mOrderAdapter.setSelectPosition(0);
        mOrderPopWindow = new PopupHelper(mContext, mOrderAdapter);
        mOrderPopWindow.setOnDisMissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                paixu.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallxiajiantou, 0);
            }
        });
        mOrderPopWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mOrderPopWindow.dismissDropDownView();
                mZhiboType = position + 1;
//                orderNo = String.valueOf(position);
                String currentOrder = (String) mOrderAdapter.getItem(position);
                paixu.setText(currentOrder);
                mAdapter.setCurrentOrder(currentOrder);
                mOrderAdapter.setSelectPosition(position);
                mListView.doRefresh();
            }
        });
    }

    private boolean isShow = false;

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        getUserDetail();
        if (!hidden) {
            isShow = true;
            if (mAdapter != null && mAdapter.getCount() == 0) {
                mListView.doRefresh();
            }
        } else {
            isShow = false;
        }
    }

    private void getUserDetail() {
        GetUserDetailTask task = new GetUserDetailTask();
        task.addListener(new MyListener(mContext));
        detailTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

    private void getTuijianList() {
        if (mTuijianListTaskId != -1) {
            return;
        }
//        int pageNo = 0;
//        if (mZhiboType == 1) {//最新
//            pageNo = currentPage;
//            if (pageNo == 0) {
//                mListView.setNoNextPage();
//                return;
//            }
//        }
        if (currentPage == 0) {
            mListView.setNoNextPage();
            return;
        }

//        if (mZhiboType == 2){//最热
//            pageNo = currentPage_h;
//            if (pageNo == 0) {
//                mHotListView.setNoNextPage();
//                return;
//            }
//
//        }
//
//        if (mZhiboType == 3){//关注的
//            pageNo = currentPage_a;
//            if (pageNo == 0) {
//                mAttentionListView.setNoNextPage();
//                return;
//            }
//        }
        //TODO
//        LiveListTask task = new LiveListTask(size, currentPage, null, null, mZhiboType, versionCode, mSubjectNo, mRegion, mLeiBie);
        LiveListTask task = new LiveListTask(size, currentPage, null, null, mZhiboType, versionCode, mSubjectNo, mRegion, mLeiBie, "0");
        task.addListener(new MyListener(mContext));
        mTuijianListTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

    @Override
    public void onClick(View v) {
        if (firstListItem <= 0) {
            if (mListView.getHeaderViewsCount() > 0) {
                mListView.post(new Runnable() {
                    @Override
                    public void run() {
                        mListView.setSelection(1);
                    }
                });

            } else {
                mListView.smoothScrollToPosition(1);
            }
        }
        switch (v.getId()) {
            case R.id.choose_region:
                region.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallshangjiantou, 0);
                mRegionPopWindow.showDropDownView(v);
                break;
            case R.id.choose_kemu:
                kemu.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallshangjiantou, 0);
                mSubjectPopWindow.showDropDownView(v);
                break;
            case R.id.choose_paixu:
                paixu.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallshangjiantou, 0);
                mOrderPopWindow.showDropDownView(v);
                break;
            case R.id.choose_leibie:
                leibie.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.smallshangjiantou, 0);
                mLeiBiePopWindow.showDropDownView(v);
                break;
        }
    }

    @Override
    public void onScroll(AbsListView listView, int firstVisiableItem, int visiableItemCount, int totalItemCount) {
        if (xuanzeLayout == null) return;
        if (mListView.getHeaderViewsCount() > 0) {
            firstVisiableItem--;
        }
        firstListItem = firstVisiableItem;
        if (firstVisiableItem >= 1) {
            xuanzeLayout.setVisibility(View.VISIBLE);
        } else {
//            xuanzeLayout.setVisibility(View.GONE);
        }
    }

    @Override
    public void onScrollStateChanged(AbsListView listView, int state) {

    }

    *//*@Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.new_button:

                mZhiboType = 1;
                mListView.setVisibility(View.VISIBLE);
//                mHotListView.setVisibility(View.GONE);
//                mAttentionListView.setVisibility(View.GONE);
                if (mAdapter!= null && mAdapter.getCount() == 0) {
                    mListView.doRefresh();
                }else {
                    getTuijianList();
                }
                break;

            case R.id.hot_button:
                mZhiboType = 2;
                mListView.setVisibility(View.GONE);
//                mHotListView.setVisibility(View.VISIBLE);
//                mAttentionListView.setVisibility(View.GONE);
//                if (mHotAdapter!= null && mHotAdapter.getCount() == 0){
//                    PalLog.e(TAG,"haihaiahi");
//                    mHotListView.doRefresh();
//                }else {
//                    getTuijianList();
//                }
                break;

            case R.id.attention_button:
                mZhiboType = 3;
                mListView.setVisibility(View.GONE);
//                mHotListView.setVisibility(View.GONE);
//                mAttentionListView.setVisibility(View.VISIBLE);
//                if (mAttentionAdapter!= null && mAttentionAdapter.getCount() == 0){
//                    mAttentionListView.doRefresh();
//                }else {
//                    getTuijianList();
//                }
                break;
        }
    }*//*

    class MyListener extends ShowToastTaskEventListener {
        public MyListener(Context context) {
            super(context);
        }

        @Override
        public void handleTaskCompleted(int taskId, int result, Object data) {
            super.handleTaskCompleted(taskId, result, data);
            if (taskId == mTuijianListTaskId) {
                mTuijianListTaskId = -1;
//                if (mListView.getVisibility() == View.VISIBLE) {
                if (currentPage == 1) {
                    mAdapter.clearData();
                    mListView.onRefreshComplete();
                    mListView.enableLoadMore();
                    mListView.setSelection(0);
                } else {
                    mListView.onLoadDataComplete(true);
                }
                List<EatShowUserInfo> fansList = new ArrayList<EatShowUserInfo>();
                if (data != null) {
                    fansList = (List<EatShowUserInfo>) data;
                }

                if (fansList != null && fansList.size() > 0) {
                    mAdapter.updateData(fansList);
                }

                if (mAdapter != null && mAdapter.getCount() > 0) {
                    noDataUtil.ListViewNoEmpty(mListView);
                } else {
                    xuanzeLayout.setVisibility(View.VISIBLE);
                    noDataUtil.ListViewEmpty(mListView, null, null, -1);
                }


                currentPage = result;
//                }
                *//*else if (mHotListView.getVisibility() == View.VISIBLE){
                    if (currentPage_h == 1) {
                        mHotAdapter.clearData();
                        mHotListView.onRefreshComplete();
                        mHotListView.enableLoadMore();
                        mHotListView.setSelection(0);
                    } else {
                        mHotListView.onLoadDataComplete(true);
                    }
                    List<EatShowUserInfo> fansList = new ArrayList<EatShowUserInfo>();
                    if (data != null) {
                        fansList = (List<EatShowUserInfo>) data;
                    }

                    if (fansList != null && fansList.size() > 0) {
                        mHotAdapter.updateData(fansList);
                    }

                    currentPage_h = result;
                }else if (mAttentionListView.getVisibility() == View.VISIBLE){
                    if (currentPage_a == 1) {
                        mAttentionAdapter.clearData();
                        mAttentionListView.onRefreshComplete();
                        mAttentionListView.enableLoadMore();
                        mAttentionListView.setSelection(0);
                    } else {
                        mAttentionListView.onLoadDataComplete(true);
                    }
                    List<EatShowUserInfo> fansList = new ArrayList<EatShowUserInfo>();
                    if (data != null) {
                        fansList = (List<EatShowUserInfo>) data;
                    }

                    if (fansList != null && fansList.size() > 0) {
                        mAttentionAdapter.updateData(fansList);
                    }

                    currentPage_a = result;
                }*//*
            } else if (taskId == schoolListTaskId) {
                if (data != null) {
                    List<SchoolInfo> schoolInfos = (List<SchoolInfo>) data;
                    if (schoolInfos != null && schoolInfos.size() > 0) {
                        mXuexiaoAdapter.clearData();
                        mXuexiaoAdapter.updateData(schoolInfos);
                    }
                }
            } else if (taskId == detailTaskId) {
                if (data != null) {
                    userInfo = (EatShowUserInfo) data;
                    if (userInfo != null) {
                        canLive = userInfo.getCanStartLive();
//                        canLive = userInfo.getFansNum();
                      *//*  if (canLive == null || canLive.equals("0")) {
                            mToZhibo.setVisibility(View.GONE);
                        }*//*
                    }
                }
            } else if (taskId == advertiseId) {
                advertiseId = -1;

                if (data != null) {
                    adList = (List<AdvertiseInfo>) data;
                    if (adList != null && adList.size() > 0) {
                        mAdapter.addImageView(adList);
                        mAdapter.notifyDataSetChanged();
                    }

                }
            }

        }

        @Override
        public void handleTaskError(int taskId, int errorCode, String errorMsg) {
            if (errorCode == TaskResultCode.NEED_LOGIN) {
                ((MainActivity) getActivity()).showFirstPage();
            }
            super.handleTaskError(taskId, errorCode, errorMsg);
            if (taskId == mTuijianListTaskId) {
                mTuijianListTaskId = -1;
//                if (mListView.getVisibility() == View.VISIBLE) {
                if (currentPage == 1) {
                    mListView.onRefreshComplete();
                } else {
                    mListView.onLoadDataComplete(false);
                }
//                }
                *//*else if (mHotListView.getVisibility() == View.VISIBLE){
                    if (currentPage_h == 1) {
                        mHotListView.onRefreshComplete();
                    } else {
                        mHotListView.onLoadDataComplete(false);
                    }
                }else if (mAttentionListView.getVisibility() == View.VISIBLE){
                    if (currentPage_a == 1) {
                        mAttentionListView.onRefreshComplete();
                    } else {
                        mAttentionListView.onLoadDataComplete(false);
                    }
                }*//*
            }
        }

        @Override
        public void handleTaskMessage(int taskId, Object data) {
            super.handleTaskMessage(taskId, data);
        }
    }


    @Override
    public void onPullRefresh() {

    }

    @Override
    public void onLoadMore() {
        getTuijianList();
    }

    @Override
    public void onRefresh() {
        currentPage = 1;
        noDataUtil.ListViewNoEmpty(mListView);
        getTuijianList();
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("ZhiBoFragment");
    }

    @Override
    public void onResume() {
        super.onResume();
        getUserDetail();
        if (isShow) {
            mListView.doRefresh();
        }
        MobclickAgent.onPageStart("ZhiBoFragment");
    }


    private void checkAppKey(String appkey) {
        String cachedAppKey = Preferences.getInstance(mContext.getApplicationContext()).getString(Preferences.KEY_APP_KEY);
        if (TextUtils.isEmpty(cachedAppKey) || !cachedAppKey.equals(appkey)) {
            Preferences.getInstance(mContext.getApplicationContext()).putString(Preferences.KEY_APP_KEY, appkey);
            Preferences.getInstance(mContext.getApplicationContext()).remove(Preferences.KEY_SESSION_ID);
            Preferences.getInstance(mContext.getApplicationContext()).remove(Preferences.KEY_USER_NUMBER);
            Preferences.getInstance(mContext.getApplicationContext()).remove(Preferences.KEY_USER_NICKNAME);
        }
    }

    private void getAdList() {
//        if (advertiseId != -1) {
//            return;
//        }
//        if (currentPageAll == 0) {
//            mListView.setNoNextPage();
//            return;
//        }

        AdvertisementTask adtask = new AdvertisementTask("3", "7");
        adtask.addListener(new MyListener(mContext));
        advertiseId = getEatShowApp().getTaskManager().addTask(adtask);
    }*/
}
